<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class reassigned_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();

	}
public function get_engineer()
	{
	$this->db->select('users.*');
	$this->db->from('users', 'users_groups' );
	$this->db->join('users_groups', 'users.id= users_groups.user_id   '  );
	$this->db->where('users_groups.group_id',2);
	$q = $this->db->get();
		if($q->num_rows() > 0) {
			foreach (($q->result()) as $row) {
				$data[] = $row;
			}
			return $data;
			
		}
	
	
	
	}		
public function get_case_detail($id)
{

	$this->db->select('case.case_no,case.service_id,reassigned_caseid.old_caseid,case.id');
	$this->db->from('case','reassigned_caseid' );
	$this->db->join('reassigned_caseid','reassigned_caseid.new_caseid=case.id');
	$this->db->where('reassigned_caseid.id',$id);
	$q = $this->db->get();
	return $q;

}	
public function old_case_update($id)
{
$insert=array('status_id'=>22,'engineer_id'=>0,);
$this->db->update('case',$insert,array('id'=>$id));

}	
public function create_diagnosis($insert)
{

$this->db->insert('diagnosis',$insert);



}	
public function get_reassigned_view()
	{
	$this->datatables
			->select("reassigned_caseid.id as id,case.case_no,status.name,users.username,diagnosis.date,customer.customer_name,customer.mobile,customer.customer_address")
			->from('customer','case','reassigned_caseid','diagnosis','users','status')
             ->join('case','customer.service_id=case.service_id')				
            ->join('reassigned_caseid','reassigned_caseid.new_caseid=case.id')	
			->join('diagnosis','diagnosis.case_id=case.id')
			->join('users','users.id=diagnosis.enginer_id')
			->join('status','diagnosis.status_id=status.id')
			->add_column("Actions",
			"<center>			<a href='index.php/admin/reassigned_case/reassigned_engineer/$1'>
								<i class='icon-edit'></i>
								</a>
								<a href='index.php/admin/reassigned_case/delete_reassigned/$1'>
								<i class='icon-trash'></i>
								</a>
								
							    </center>", "id")
			
			;
	   return  $this->datatables->generate();
	}	
	
public function get_notreassigned_view()
	{ 
	$this->datatables
			->select("reassigned_caseid.id as id,reassigned_caseid.old_caseid,case.case_no,reassigned_caseid.date,customer.customer_name,customer.mobile,customer.customer_address")
			->from('customer','case','reassigned_caseid')
             ->join('case','customer.service_id=case.service_id')				 
            ->join('reassigned_caseid','reassigned_caseid.new_caseid=case.id')
		    ->where('case.engineer_id',0)
			->where('case.status_id',0)
			->add_column("Actions",
			"<center>			<a href='index.php/admin/reassigned_case/reassigned_engineer/$1'>
								<i class='icon-edit'></i>
								</a>
								<a href='index.php/admin/reassigned_case/delete_reassigned/$1'>
								<i class='icon-trash'></i>
								</a>
								
							    </center>", "id")
			
			;
	   return  $this->datatables->generate();
	}	
	
public function update_case($id,$eng_id)
{
$insert=array('engineer_id'=>$eng_id,'status_id'=>1,);
$this->db->update('case',$insert,array('id'=>$id));



}
	}
	?>